﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ShowPage_webJJ : System.Web.UI.Page
{
    Operation operation = new Operation();
    static string infoType = "";
    static string infoKey = "";
    static string staDay = "";
    static string endDay = "";
    static string subTypeId = "0";
    static PagedDataSource pds = new PagedDataSource();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BuildList(new object(), new EventArgs());
            SearchBt_onClick(new object(), new EventArgs());
        }
    }
    /// <summary>
    /// 将数据绑定到DataList控件
    /// </summary>
    public void DataListBind()
    {
        if (staDay == "") staDay = "2010-10-1";
        if (endDay == "") endDay = DateTime.Now.ToString("yyyy-MM-dd", new System.Globalization.CultureInfo("zh-cn"));
        //if (one.Text.CompareTo("全部") == 0)//函数内部能判断；对应页面的全部分类搜索选项
        pds = operation.PageDataListBind(infoType, infoKey, subTypeId, staDay, endDay,
            this.tbComname.Text.Trim(),this.tbCominfo.Text.Trim(),Convert.ToInt32(lblCurrentPage.Text), 10);
        lnkBtnFirst.Enabled = true;　　　　　　//控件翻页控件都设置为可用
        lnkBtnLast.Enabled = true;
        lnkBtnNext.Enabled = true;
        lnkBtnPrevious.Enabled = true;
        if (lblCurrentPage.Text == "1")　　　//如果当前显示第一页，“第一页”和“上一页”按钮不可用。
        {
            lnkBtnPrevious.Enabled = false;
            lnkBtnFirst.Enabled = false;
        }
        if (lblCurrentPage.Text == pds.PageCount.ToString())　　//如果显示最后一页，“末一页”和“下一页”按钮不可用。
        {
            lnkBtnNext.Enabled = false;
            lnkBtnLast.Enabled = false;
        }
        lblSumPage.Text = pds.PageCount.ToString();　　//实现总页数
        dlFree.DataSource = pds;　　　　　　　　　　　 //绑定数据源
        dlFree.DataKeyField = "id";
        dlFree.DataBind();
    }
    protected void lnkBtnFirst_Click(object sender, EventArgs e)
    {
        lblCurrentPage.Text = "1";
        DataListBind();
    }
    protected void lnkBtnPrevious_Click(object sender, EventArgs e)
    {
        lblCurrentPage.Text = (Convert.ToInt32(lblCurrentPage.Text) - 1).ToString();
        DataListBind();
    }
    protected void lnkBtnNext_Click(object sender, EventArgs e)
    {
        lblCurrentPage.Text = (Convert.ToInt32(lblCurrentPage.Text) + 1).ToString();
        DataListBind();
    }
    protected void lnkBtnLast_Click(object sender, EventArgs e)
    {
        lblCurrentPage.Text = lblSumPage.Text;
        DataListBind();
    }
    public void BuildList(object sender, EventArgs e)
    {
        if (one.Text.IndexOf("技术") == -1)
        {
            dlCategory.Visible = false;
        }
        else
        {
            dlCategory.Visible = true;
            dlCategory.Items.Clear();
            BuildDownList("0", "", "---");
        }
        SearchBt_onClick(new object(), new EventArgs());
    }
    public void BuildDownList(string pid, string itH, string dx)//itH为表项前度，dx为递增前度
    {
        DataSet ds = operation.SelectCategoryByPID(pid);//一级类别
        int count = ds.Tables[0].Rows.Count;
        string t = itH + dx;//下级前度
        for (int i = 0; i < count; i++)
        {
            ListItem item = new ListItem();
            item.Value = ds.Tables[0].Rows[i][0].ToString();
            item.Text = itH + ds.Tables[0].Rows[i][1].ToString();
            dlCategory.Items.Add(item);
            BuildDownList(item.Value, t, dx);
        }
    }
    protected void SearchBt_onClick(object sender, EventArgs e)
    {
        infoType = one.Text;
        infoKey = txtKey.Text.Trim();
        staDay = CalendarInputSta.Text.Trim();
        endDay = CalendarInputEnd.Text.Trim();
        if (one.SelectedValue.CompareTo("技术供应信息") == 0 || one.SelectedValue.CompareTo("技术需求信息") == 0 )
        {
            subTypeId = dlCategory.Text;
            if (subTypeId == "") subTypeId = "0";
        }
        else if (one.Text.CompareTo("全部") == 0)
        {
            subTypeId = "none";
        }
        else
        {
            subTypeId = "0";
        }
        
        DataListBind();
        
    }
}
